<?php
include("admin_check.php");
include_once("../function.php");

$sql="select sum(b0),sum(b1),sum(b2),sum(b3) from bonus where 1=1";
$query=mysql_query($sql);
$row=mysql_fetch_assoc($query);
$a1=$row['sum(b1)'];
$a2=$row['sum(b2)'];
$a3=$row['sum(b3)'];
$a0=$row['sum(b0)'];
if($a0>0){
    $b1=round($a1/$a0,2);
    $b2=round($a2/$a0,2);
    $b3=round($a3/$a0,2);
    $arr=array(
        array('name'=>'奖金1','value'=>$b1),
        array('name'=>'奖金2','value'=>$b2),
        array('name'=>'奖金3','value'=>$b3)
    );
    $chartData = json_encode($arr);
}



session_start();
header("Content-Type: text/html;charset=utf-8");
checkqx(3,19);
if ($_POST['Search']){
	$SearchContent=$_POST['SearchContent'];
	$TimeStart=$_POST['TimeStart'];
	$TimeEnd=$_POST['TimeEnd'];
	$SearchType=$_POST['SearchType'];
	if ($TimeStart!=NULL){
		if ($TimeEnd==NULL){
			$TimeEnd=now();	
		}
		$_SESSION['SearchTime']="and jsdate>='".$TimeStart."' and jsdate<='".$TimeEnd."'";	
	}else{
		$_SESSION['SearchTime']=NULL;		
	}
}else{
	if ($_GET['page']==NULL){
		$_SESSION['Search']=NULL;	
		$_SESSION['SearchTime']=NULL;
	}
}

?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="css/table.css" rel="stylesheet" type="text/css">
<link href="css/style.css" rel="stylesheet" type="text/css">
<script src="../js/calendar.js"></script>
<script src="./public/echarts.js"></script>
    <link href="../layui-master/dist/css/layui.css" rel="stylesheet" type="text/css">
    <script src="../layui-master/dist/layui.js"></script>
<title>奖金查询</title>
    <script>
        layui.use('laydate', function(){
            var laydate = layui.laydate;

            //执行一个laydate实例
            laydate.render({
                elem: '#TimeStart' //指定元素
            });
            laydate.render({
                elem: '#TimeEnd' //指定元素
            });
        });
    </script>
</head>
<body>
<form name="form1" method="post" action="?">
    <table width="100%" cellpadding="3" cellspacing="1" border="0" align="center" class="layui-table" lay-skin="line">
        <tr>
            <td height="4" colspan="11" align="left">搜索时间范围：
                <input type="text" name="TimeStart" id="TimeStart" style="width:100px" >
                至
                <input type="text" name="TimeEnd" id="TimeEnd" style="width:100px" ><input type="submit" name="Search" id="Search" class="layui-btn layui-btn-small" value="搜索"></td>
        </tr>
        <tr>
            <td align="center">日期</td>
            <td align="center">新增会员</td>
            <td align="center">会员总数</td>
            <td align="center">新增业绩</td>
            <td align="center">业绩总数</td>
            <td align="center">奖金发放</td>
            <td align="center">发放总数</td>
            <td align="center">拨比</td>
            <td align="center">总拨比</td>
        </tr>
        <?php
        $pagesize = 20; //设置每页记录数
        $sql = "SELECT * FROM `systemyeji` WHERE 1=1 ".$_SESSION['Search']." ".$_SESSION['SearchTime']."";
        if($query = mysql_query($sql)){
            $sum = mysql_num_rows($query); //计算总记录数
        }else{
            $sum=0;
        }
        if($sum % $pagesize == 0) //计算总页数
            $total = (int)($sum/$pagesize);
        else
            $total = (int)($sum/$pagesize) + 1;
        if (isset($_GET['page'])) //获得页码
        {
            $p = (int)$_GET['page'];
        }
        else
        {
            $p = 1;
        }
        if ($p>$total){
            $p=$total;
        }
        $start = $pagesize * ($p - 1); //计算起始记录
        $sql = "SELECT * FROM `systemyeji` WHERE 1=1 ".$_SESSION['Search']." ".$_SESSION['SearchTime']." order by ydate desc limit ".$start.",".$pagesize;
        if($query = mysql_query($sql)){
            while ($row=mysql_fetch_array($query)){
                ?>
                <tr>
                    <td align="center"><?=date("Y-m-d H:s:i",strtotime($row['ydate']))?></td>
                    <td align="center"><?=$row['xzhy']?></td>
                    <td align="center"><?=$row['zhy']?></td>
                    <td align="center"><?=$row['xzyj']?></td>
                    <td align="center"><?=$row['zyj']?></td>
                    <td align="center"><?=$row['ff']?></td>
                    <td align="center"><?=$row['zff']?></td>
                    <td align="center"><?=$row['ff']/$row['xzyj']*100?>%</td>
                    <td align="center"><?=$row['zff']/$row['zyj']*100?>%</td>
                </tr>
                <?php
            }
        }
        ?>
        <tr>
            <td height="21" colspan="11" align="right">
                <table width="100%" border="0">
                    <tr>
                        <td align="right"><?php echo fenye($p,$pagesize,$sum,$total,$cx)?></td>
                    </tr>
                </table></td>
        </tr>
    </table>
</form>
<div id="main" style="width: 600px;height:400px;"></div>
<script type="text/javascript">
    // 基于准备好的dom，初始化echarts实例
    var myChart = echarts.init(document.getElementById('main'));
    var chartData = '<?php echo $chartData; ?>';
    myChart.setOption({
        series : [
            {
                title:'奖金发放分布图',
                name: '访问来源',
                type: 'pie',
                radius: '55%',
                data: JSON.parse(chartData)
            }
        ]
    })

    myChart.setOption(option);
</script>

</body>
</html>